require File.dirname(__FILE__) + '/../../../lib/dotnet/framework'
require 'test/unit'
require 'mocha'

class  WhenGettingFrameworkInformation < Test::Unit::TestCase
  
  def test_should_load_frameworks_if_not_already_loaded
    framework = 'framework'
    ENV['framework'] = framework
    configatron.frameworks.stubs(:nil?).returns(true)
    configatron.expects(:configure_from_yaml)
    configatron.frameworks.stubs(:retrieve).with(framework).returns({framework => {}})
    Rubicant::DotNet::Framework.stubs(:new).returns(mock())
    
    Rubicant::DotNet::Frameworks.get_framework()
    
  end
  
  def test_should_fail_if_requested_framework_is_not_in_configuration
    begin
      framework = 'framework'
      ENV['framework'] = framework
      configatron.frameworks.stubs(:nil?).returns(false)
      configatron.frameworks.stubs(:retrieve).with(framework).returns(nil)
      
      Rubicant::DotNet::Frameworks.get_framework()
      
      fail('I wanted a runtime error to be thrown')
    rescue RuntimeError => re
      assert_equal(re.message, 'Requested framework does not exist in configuration')
    end
    
  end
  
  def test_should_get_back_framework_if_exists_in_configuration
    framework = mock()
    frameworkName = 'framework'
    ENV['framework'] = frameworkName
    frameworkConfiguration = {frameworkName => {}}
    
    configatron.frameworks.stubs(:nil?).returns(false)
    configatron.frameworks.stubs(:retrieve).with(frameworkName).returns(frameworkConfiguration)
    
    Rubicant::DotNet::Framework.expects(:new).with(frameworkConfiguration).returns(framework)
    
    result = Rubicant::DotNet::Frameworks.get_framework()
    assert_equal framework, result
    
  end
  
  def test_should_default_to_net35_if_no_framework_specified
    framework = mock()
    ENV['framework'] = nil
    frameworkConfiguration = {'net35' => {}}
    
    configatron.frameworks.stubs(:nil?).returns(false)
    configatron.frameworks.expects(:retrieve).with('net35').returns(frameworkConfiguration)
    frameworkConfiguration.stubs(:nil?).returns(false)
    Rubicant::DotNet::Framework.stubs(:new).with(frameworkConfiguration).returns(framework)
    
    Rubicant::DotNet::Frameworks.get_framework()
  end
  
end